//
//  NYMyExamineCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/8.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYMyExamineCell.h"
@interface NYMyExamineCell ()
@property(nonatomic, strong) TTTAttributedLabel *titleLabel;
@property(nonatomic, strong) TTTAttributedLabel *scoreLabel;
@property(nonatomic, strong) TTTAttributedLabel *usedTimeLabel;
@property(nonatomic, strong) UIProgressView *progressView;
@property(nonatomic, strong) TTTAttributedLabel *totalTimeLabel;
@property(nonatomic, strong) TTTAttributedLabel *dateLabel;
@property(nonatomic, strong) QMUIButton *arrowBtn;
@property (nonatomic, strong) UIImageView *lineImgView;
@end
@implementation NYMyExamineCell
+ (CGFloat)heightForObject:(NYMyExamineModel *)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
        return [tableView fd_heightForCellWithIdentifier:identifier cacheByIndexPath:indexPath configuration:^(NYMyExamineCell * cell) {
                cell.examineModel = object;
        }];
}
- (BOOL)shouldUpdateCellWithObject:(id)object
{
        self.examineModel = object;
        return YES;
}
- (void)setExamineModel:(NYMyExamineModel *)examineModel
{
        _examineModel = examineModel;
        [self updateContent];
}
- (void)updateContent
{
        self.titleLabel.text = self.examineModel.ex_title;
        self.scoreLabel.text = [NSString stringWithFormat:@"得分：%@分",NOT_NULL_STRING(self.examineModel.score, @"00:00:00")];
        NSMutableAttributedString *attrM = [[NSMutableAttributedString alloc] initWithString:@"用时 " attributes:@{
                                                                                                                 NSForegroundColorAttributeName : UIColorHex(0x999999),
                                                                                                                 NSFontAttributeName : WGSystem12Font
                                                                                                                 }];
        [attrM appendAttributedString:[[NSAttributedString alloc] initWithString:NOT_NULL_STRING(self.examineModel.ystime, @"0") attributes:@{
                                                                                                  NSForegroundColorAttributeName : UIColorHex(0x333333),
                                                                                                  NSFontAttributeName : WGSystem12Font
                                                                                                  }]];
        self.usedTimeLabel.attributedText = attrM;
//        self.progressView.progress = ysTimeMinute / 90.0;
        self.progressView.hidden = YES;
//        self.totalTimeLabel.text = [NSString stringWithFormat:@"总时间：%@分钟",NOT_NULL_STRING(self.examineModel.kstime, @"0")];
//        self.totalTimeLabel.text = @"总时间：90分钟";
        self.dateLabel.text = [AppUnit formatGMT8TimeMillisecond:self.examineModel.kstime.integerValue * 1000 withFormat:@"yyyy-MM-dd HH:mm:ss"];
}
- (void)setupView
{
        [super setupView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.scoreLabel];
        [self.contentView addSubview:self.usedTimeLabel];
        [self.contentView addSubview:self.progressView];
        [self.contentView addSubview:self.totalTimeLabel];
        [self.contentView addSubview:self.dateLabel];
        [self.contentView addSubview:self.arrowBtn];
        [self.contentView addSubview:self.lineImgView];
        
        [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.contentView).offset(__WGHeight(15));
                make.left.equalTo(self.contentView).offset(__WGWidth(15));
        }];
        
        [self.scoreLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.contentView).offset(__WGHeight(15));
                make.right.equalTo(self.contentView).offset(-__WGWidth(15));
                make.left.greaterThanOrEqualTo(self.titleLabel.mas_right).offset(__WGWidth(15));
        }];
        
        [self.usedTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.titleLabel.mas_bottom).offset(__WGHeight(15));
                make.right.lessThanOrEqualTo(self.scoreLabel.mas_right);
                make.left.equalTo(self.titleLabel.mas_left);
        }];
        
        [self.progressView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.usedTimeLabel.mas_bottom).offset(__WGHeight(10));
                make.left.equalTo(self.titleLabel.mas_left);
                make.right.lessThanOrEqualTo(self.scoreLabel.mas_right);
                //                make.width.mas_equalTo(__WGWidth(192));
                make.height.mas_equalTo(__WGHeight(6));
        }];
        
        [self.totalTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.progressView.mas_right).offset(__WGWidth(5));
                make.centerY.equalTo(self.progressView);
                make.right.equalTo(self.contentView).offset(-__WGWidth(78));
        }];
        
        [self.dateLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.progressView.mas_bottom).offset(__WGHeight(15));
                make.right.lessThanOrEqualTo(self.scoreLabel.mas_right);
                make.left.equalTo(self.titleLabel.mas_left);
        }];
        
        [self.arrowBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.contentView.mas_right).offset(-__WGWidth(15));
                make.centerY.equalTo(self.contentView);
        }];
        
        [self.lineImgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.dateLabel.mas_bottom).offset(__WGHeight(15));
                make.right.equalTo(self.contentView);
                make.left.equalTo(self.titleLabel.mas_left);
                make.bottom.equalTo(self.contentView).priorityLow();
                make.height.mas_equalTo(__WGHeight(1));
        }];
}
/// MARK: - Lazy
- (UIProgressView *)progressView
{
        if (_progressView == nil) {
                _progressView = [[UIProgressView alloc] init];
                _progressView.progressTintColor = UIColorHex(0xFFAE00);
                _progressView.trackTintColor = UIColorHex(0xDDDDDD);
        }
        return _progressView;
}
- (UIImageView *)lineImgView {
        if (!_lineImgView) {
                _lineImgView = [[UIImageView alloc] initWithFrame:CGRectZero];
                _lineImgView.backgroundColor = UIColorSeparator;
        }
        return _lineImgView;
}
- (QMUIButton *)arrowBtn
{
        if (_arrowBtn == nil) {
                _arrowBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImage jian_tou] title:nil];
        }
        return _arrowBtn;
}
- (TTTAttributedLabel *)titleLabel
{
        if (_titleLabel == nil) {
                _titleLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _titleLabel.font = WGSystem14Font;
                _titleLabel.textColor = UIColorHex(0x333333);
                [_titleLabel setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)];
        }
        return _titleLabel;
}
- (TTTAttributedLabel *)scoreLabel
{
        if (_scoreLabel == nil) {
                _scoreLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _scoreLabel.font = WGSystem12Font;
                _scoreLabel.textColor = UIColorHex(0xFFAE00);
                [_scoreLabel setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh) forAxis:(UILayoutConstraintAxisHorizontal)];
        }
        return _scoreLabel;
}
- (TTTAttributedLabel *)usedTimeLabel
{
        if (_usedTimeLabel == nil) {
                _usedTimeLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _usedTimeLabel.font = WGSystem12Font;
                _usedTimeLabel.textColor = UIColorHex(0x333333);
        }
        return _usedTimeLabel;
}
- (TTTAttributedLabel *)totalTimeLabel
{
        if (_totalTimeLabel == nil) {
                _totalTimeLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _totalTimeLabel.font = WGSystem12Font;
                _totalTimeLabel.textColor = UIColorHex(0x999999);
                [_totalTimeLabel setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh) forAxis:(UILayoutConstraintAxisHorizontal)];
        }
        return _totalTimeLabel;
}
- (TTTAttributedLabel *)dateLabel
{
        if (_dateLabel == nil) {
                _dateLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _dateLabel.font = WGSystem12Font;
                _dateLabel.textColor = UIColorHex(0x999999);
        }
        return _dateLabel;
}

@end
